#----------------------------------------------------------------------
#begining of functions
#----------------------------------------------------------------------

#the first function will upload number from user and return it

def get_number():
    while True:                                                 #funtion will be looped until user will input a total number

        number = raw_input("enter total number:")              

        if number.isdigit():                                    #when player inputs a total number the function will return it and break the loop
            return number
            break

        print "this is not a total number please try again"     #after inputing not a total number an statement will inform about it



#next function will ask the user to continue or not until correct answer

def repeat_check():
    repeat = None                                               #to avoid eventual errors the programe will reset the value of repeat

    while True:                                                 #the function will be looped until user will choose correctly

        answer = raw_input("repeat?(Y/N):")

        if (answer == "y" or answer == "Y"):                    #if user replies with Y or y repeat will be True
            repeat = True

        if (answer == "n" or answer == "N"):                    #if user replies with N or n repeat will be False
            repeat = False

        if (repeat == False or repeat == True):                 #if user replied correctly the loop will break and function will return repeat
            return repeat
            break


        print "please use Y or N only"                          #if user fails at replying a statement will inform him about it



#this function will save each number into a file

def save_number(num):
    num = num + ","                                             #before saving each number is separated with: ','


    fo = open("/20130519/20130519_save.txt", "a")                      #writing number into a file and closing it
    fo.write(num)
    fo.close


#this function will read raw numbers from a file and create a list with them

def read_data():
    fo = open("/20130519/20130519_save.txt", "r")                      #reading from a file and removal of last ','
    nums = fo.read()
    nums = nums[:-1]

    stats = nums.split(",")                                     #converting string into a table
   
    fo.close
    return stats                                                #returning stats and closing a file


def int_statistics(stats):
    l = 0

    while l < len(stats):
        stats[l] = int(stats[l])
        l = l + 1

    return stats


#from got table this function will find biggest and smallest number and the ammount of them

def print_statistics(i_stats):

    num_count = len(i_stats)                                       #ammount of numbers
    num_min = min(i_stats)                                         #smallest number
    num_max = max(i_stats)                                         #biggest number

    return "numbers count:%s, max number:%s, min number:%s" % (num_count, int(num_max), int(num_min) ) #the function will return this string containing ammount of numbers and biggest and smallest ones

#----------------------------------------------------------------------
#end of functions
#----------------------------------------------------------------------


while True:
    number = get_number()                                       #ascription of got number into a variable

    save_number(number)

    if repeat_check() == False:                                 #if user says so the aquirement of numbers will end
        break

statistics = read_data()                                        #ascription of read data into a variable

i_statistics = int_statistics(statistics)

print print_statistics(i_statistics)                              #printing statistics returned from a function


